import 'package:json_annotation/json_annotation.dart';
import 'package:retrofit/retrofit.dart';
import 'package:dio/dio.dart';
import '../../constants.dart';
import '../http/base_dio.dart';

part 'user_api.g.dart';

@RestApi(baseUrl: kBaseUrl)
abstract class UserApi {
  factory UserApi({Dio dio, String baseUrl}) {
    dio ??= BaseDio.getInstance().getDio();
    return _UserApi(dio, baseUrl: baseUrl);
  }

  @POST("/login/stu") //学生登录
  Future<LoginResponse> studentLogin(@Body() LoginBody body);

  @POST("/login/tutor") //老师登录
  Future<LoginResponse> teacherLogin(@Body() LoginBody body);

  @POST("/api/v1/logout") //退出登录
  Future<LogoutResponse> logout();

  @GET("/api/v1/user/myinfo") //获取个人信息
  Future<UserInfoResponse> userInfo();

  @GET("/api/v1/myteachers") //获取我的老师
  Future<TeacherResponse> myTeachers();
}

@JsonSerializable()
class TeacherResponse {
  String requestId;
  String msg;
  int code;
  List<Teacher> data;

  TeacherResponse({this.code, this.data,this.requestId,this.msg});

  factory TeacherResponse.fromJson(Map<String, dynamic> json) =>
      _$TeacherResponseFromJson(json);
}
@JsonSerializable()
class Teacher {
  int uid;
  String name; //名称
  String portrait;//头像
  Teacher({this.uid, this.name,this.portrait});

  factory Teacher.fromJson(Map<String, dynamic> json) => _$TeacherFromJson(json);
}




@JsonSerializable()
class LoginResponse {
  int code;
  String msg;
  String token;
  String expire;
  String upload;

  LoginResponse({this.code, this.token, this.expire, this.upload,this.msg});

  factory LoginResponse.fromJson(Map<String, dynamic> json) =>
      _$LoginResponseFromJson(json);
}

@JsonSerializable()
class LoginBody {
  String account; // 分配的账号
  String code; // 组织机构代码（相当于传统的密码)
  String host; // 登录的主机名称（可以用MEID，或者基于统一算法的uuid
  int device; // 设备类型 Android ,ios,tv,web.....默认301是web
  String ver;

  LoginBody(this.account, this.code, this.host, this.device,this.ver);

  Map<String, dynamic> toJson() => _$LoginBodyToJson(this);
}

@JsonSerializable()
class LogoutResponse {
  int code;
  String msg;

  LogoutResponse({this.code, this.msg});

  factory LogoutResponse.fromJson(Map<String, dynamic> json) =>
      _$LogoutResponseFromJson(json);
}

@JsonSerializable()
class UserInfoResponse {
  String requestId;
  int code;
  String msg;
  UserInfo data;

  UserInfoResponse({this.requestId, this.code, this.data,this.msg});

  factory UserInfoResponse.fromJson(Map<String, dynamic> json) =>
      _$UserInfoResponseFromJson(json);
}

@JsonSerializable()
class ClassInfo {
  int classid; // 班级id
  String classname; // 班级名称
  String userid; // 班主任uid

  ClassInfo({this.classid, this.classname, this.userid});

  factory ClassInfo.fromJson(Map<String, dynamic> json) =>
      _$ClassInfoFromJson(json);
}

@JsonSerializable()
class UserInfo {
  List<ClassInfo> classes; // 班级数组
  String username; // 用户名称
  String portrait; // 用户头像
  int gender; // 男女
  String role; // 角色  stu--学生  tutor--老师  master--校长 其他权限不设计客户端。
  String uid; // 用户uid
  String org; // 教育机构
  int status; // 0--账号未激活，1--账号激活
  int vip; // 0--非会员，1，2，3---将来可以扩展为几级会员，目前暂不做这个功能，所以都是0
  String nickname;

  UserInfo(
      {this.username,
      this.portrait,
      this.gender,
      this.role,
      this.uid,
      this.org,
      this.classes,
      this.status,
      this.vip,
      this.nickname});

  factory UserInfo.fromJson(Map<String, dynamic> json) =>
      _$UserInfoFromJson(json);
}
